package com.joey.concurrency.example.singleton;

import com.joey.concurrency.annotation.NotThreadSafe;
import lombok.extern.slf4j.Slf4j;

/**
 * 懒汉模式
 * 单例实例在第一次使用时创建
 * @Author hyy
 **/
@Slf4j
@NotThreadSafe
public class SingtonExample {

    private SingtonExample(){
        //资源处理，运算等等
    }

    private static SingtonExample instance = null;

    //加上sync，则线程安全
    public static SingtonExample getInstance(){
        if (instance == null){
            return new SingtonExample();
        }
        return instance;
    }
}
